#include <stdio.h>
#include <stdlib.h>

typedef struct date {
    int year;
    int month;
    int day;
} Date;

int compareDates(const void *a, const void *b) {
    Date *dateA = (Date *)a;
    Date *dateB = (Date *)b;


    if (dateA->year != dateB->year) {
        return dateA->year - dateB->year;
    }
 
    if (dateA->month != dateB->month) {
        return dateA->month - dateB->month;
    }
    return dateA->day - dateB->day;
}


void sortDate(Date dates[], int n) {
    qsort(dates, n, sizeof(Date), compareDates);
}


void printDates(Date dates[], int n) {
    for (int i = 0; i < n; i++) {
        printf("%d-%02d-%02d ", dates[i].year, dates[i].month, dates[i].day);
        printf("\n");
    }
}

int main() {
    Date dates[] = {
        {2003, 5, 5},
        {2009, 2, 7},
        {2009, 2, 20},
        {2020, 2, 29}
    };
    int n = sizeof(dates) / sizeof(dates[0]);

    printf("Before sorting:\n");
    printDates(dates, n);

    sortDate(dates, n);

    printf("After sorting:\n");
    printDates(dates, n);

    return 0;
}